package com.by.bean;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 购物车
 * </p>
 *
 * @author wyh
 * @since 2025-04-14
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("shop_cart_item")
@ApiModel(value="ShopCartItem对象", description="购物车")
public class ShopCartItem implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @TableId(value = "cart_item_id", type = IdType.AUTO)
    private Long cartItemId;


    @ApiModelProperty(value = "店铺ID")
    @TableField("shop_id")
    private Long shopId;

    @ApiModelProperty(value = "产品ID")
    @TableField("spu_id")
    private Long spuId;

    @ApiModelProperty(value = "SkuID")
    @TableField("sku_id")
    private Long skuId;

    @ApiModelProperty(value = "用户ID")
    @TableField("user_id")
    private Long userId;

    @ApiModelProperty(value = "购物车产品个数")
    @TableField("count")
    private Integer count;

    @ApiModelProperty(value = "售价，加入购物车时的商品价格")
    @TableField("price_fee")
    private Long priceFee;

    @ApiModelProperty(value = "是否已勾选")
    @TableField("is_checked")
    private Integer isChecked;

    // 以下是新增的瞬态字段，不存入数据库
    @TableField(exist = false)
    @ApiModelProperty(value = "商品名称")
    private String skuName;

    @TableField(exist = false)
    @ApiModelProperty(value = "商品图片")
    private String skuImg;

    @TableField(exist = false)
    @ApiModelProperty(value = "商品规格")
    private String skuSpec;

//    @TableField(exist = false)
//    @ApiModelProperty(value = "当前价格")
//    private Long currentPrice;

    @TableField(exist = false)
    @ApiModelProperty(value = "总金额")
    private long totalFee; // 总金额

//    // 计算总价的方法
//    public long getTotalFee() {
//        return priceFee * count;
//    }

    // 检查是否选中
    public boolean isChecked() {
        return isChecked != null && isChecked == 1;
    }

    // 设置选中状态
    public ShopCartItem setChecked(Boolean checked) {
        this.isChecked = checked ? 1 : 0;
        return this;
    }

}
